<?php
/*
 Template Name: Kader
*/

$key = 'anzug-nummer';
$args = array( 'post_type' => 'player', 'meta_key'=> $key,  'orderby' => 'meta_value_num', 'order' => ASC , 'posts_per_page' => -1);
$loop = new WP_Query( $args );
$single = true;
$taxonomy = 'position';

get_header();
?>

<div id="primary">
	<nav role="navigation" class="site-navigation page-navigation">
			<h1 class="assistive-text"><?php _e( 'Menu', 'tsv-bierden' ); ?></h1>
			<div class="assistive-text skip-link"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'tsv-bierden' ); ?>"><?php _e( 'Skip to content', 'tsv-bierden' ); ?></a></div>

			<?php wp_nav_menu( array( 'theme_location' => 'secondary' ) ); ?>
	</nav>
	<?php get_sidebar(); ?> 	
</div> <!-- #primary -->
<div id="secondary">
	<div id="content" role="main">
		<nav id="player-menu">
			<?php $terms = get_terms($taxonomy, array('orderby' => 'id', 'order' => 'ASC',));
			if ( !empty($terms) && !is_wp_error($terms) ) {
				$count = count($terms);
				if ( $count > 0 ){
					echo "<ul>";
					foreach ( $terms as $term ) {
						echo "<li id=" . $term->name . ">" . $term->name . "</li>";
				
					}
					echo "</ul>";
				}
			}
			?>
		</nav>
		<div id="player-content">
			<?php while ( $loop->have_posts() ) : $loop->the_post();?>
				<?php
					$post_id = get_the_ID();
					$number = get_post_meta($post_id, $key, $single);
					$permalink = get_permalink( $post_id ); 
					$positionArray = wp_get_post_terms( $post_id, $taxonomy, array("fields" => "names"));
					if ( !empty($positionArray) && !is_wp_error($positionArray) ) {
						$position = implode(' ', $positionArray);
						$posistion = ''; 
					}
				?>
					<article id="post-<?php the_ID(); ?>" <?php if (!empty($position)) { post_class($position); } else { post_class(); }; ?>>
						<a href="<?php echo $permalink; ?>">
							<div class="description">
								<span class="number"><p><?php echo $number; ?></p></span>
							</div> <!-- .description -->
								<?php if ( has_post_thumbnail( $post_id ) ) the_post_thumbnail( 'full' );
									else { ?>
										<div id="no-image"></div>
									<?php } ?>		
						</a>
					</article> <!-- .entry-content -->
			
			<?php endwhile; // end of the loop. ?>
		</div> <!-- #player-content -->
	</div>	<!-- #content -->
</div> <!-- #secondary -->

<?php get_footer(); ?>